package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Course;
import cn.hl.sfzy.entity.CourseMark;
import cn.hl.sfzy.entity.CourseType;
import cn.hl.sfzy.service.CourseMarkService;
import cn.hl.sfzy.service.CourseService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseMarkController
 * @Description TODO
 * @Author libowen
 * @Date 2024年10月26日 14:33
 * @Version 1.0
 */
@RestController
@RequestMapping("/CourseMark")
@CrossOrigin
public class CourseMarkController {
    @Autowired
    private CourseMarkService courseMarkService;

    @GetMapping("/findByCourseId")
    public Result selectByCourseId(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize,Long course_id) {
        PageInfo<CourseMark> courseMarks = courseMarkService.findByCourseId(pageNum,pageSize,course_id);
        return Result.success(courseMarks);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        int i = courseMarkService.deleteCourseMark(id);
        return Result.success("删除成功");
    }
    @PostMapping
    public Result insert(@RequestBody CourseMark courseMark) {
        int i = courseMarkService.addCourseMark(courseMark);
        return Result.success(courseMark);
    }
    @PutMapping
    public Result update(@RequestBody CourseMark courseMark) {
        int i = courseMarkService.updateCourseMark(courseMark);
        return Result.success(courseMark);
    }
    @GetMapping
    public Result pageSelect(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize, CourseMark courseMark) {
        PageInfo<CourseMark> byPage = courseMarkService.findByPage(pageNum, pageSize, courseMark);
        return Result.success(byPage);
    }
}
